package org.window;

import com.scm.all.struct.TagMemoryDataX86;
import com.scm.x86.export.MemoryOperationUtilsX86;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.util.Callback;
import org.apache.commons.lang3.StringUtils;
import org.openProcess.StageWindowsProcessAndListView;
import org.showData.StageWindowShow;
import org.showData.StageWindowShowAndPaneAndVBoxAndHBoxAndLableTextFind;

import java.util.Arrays;

/**
 * 数据列表
 */
public class PaneAndHBoxFrameAndColumnAndTableView {
    public static TableView<TagMemoryDataX86> tableView = new TableView<>();
    public static TableColumn tableColumn0 = new TableColumn<>("静态");
    public static TableColumn tableColumn1 = new TableColumn<>("十进制地址");
    public static TableColumn tableColumn2 = new TableColumn<>("十六进制地址");
    public static TableColumn tableColumn3 = new TableColumn<>("内存属性");
    public static TableColumn tableColumn4 = new TableColumn<>("内存类型");
    public static TableColumn tableColumn5 = new TableColumn<>("内存数据");
    public static ObservableList<TagMemoryDataX86> data = FXCollections.observableArrayList();
    public static boolean flag =false;
    public static int index;
    public static Thread thread;
    public static void init() {
        tableView.setPrefWidth(400);
        tableColumn0.setPrefWidth(50);
//        tableColumn5.setPrefWidth(500);
//        tableView.getColumns().addAll(tableColumn0,tableColumn1,tableColumn2,tableColumn3,tableColumn4);
        tableView.getColumns().addAll(tableColumn0,tableColumn1,tableColumn2,tableColumn3,tableColumn4,tableColumn5);
        tableColumn0.setCellValueFactory(new PropertyValueFactory<>("IsStatic"));
        tableColumn1.setCellValueFactory(new PropertyValueFactory<>( "tenAddress"));
        tableColumn2.setCellValueFactory(new PropertyValueFactory<>( "HexAddress"));
        tableColumn3.setCellValueFactory(new PropertyValueFactory<>("MemoryProtect"));
        tableColumn4.setCellValueFactory(new PropertyValueFactory<>( "MemoryType"));
        tableColumn5.setCellValueFactory(new PropertyValueFactory<>( "MemoryMessage"));
//        tableView.getSelectionModel().getSelectedItems().addListener(new ListChangeListener<String>() {
//            @Override
//            public void onChanged(Change<? extends String> c) {
//                if(!StageWindowShow.stage.isShowing()){
//                    StageWindowShow.stage.show();
//                }
//                Platform.runLater(new Runnable() {
//                    @Override
//                    public void run() {
//                        if(c.getList().get(0)!=null){
////                            StageWindowShowAndPaneAndVBoxAndHBoxAndLableTextFind.textField.setText(""+c.getList().get(0).tenAddress);
//                        }
//
//                    }
//                });
////                index = tableView.getSelectionModel().getSelectedIndex();
////                flag =false;
////                thread = new Thread(new Runnable() {
////                    @Override
////                    public void run() {
////                        while (flag){
////                            try {
////                                Thread.sleep(100);
////                                Platform.runLater(new Runnable() {
////                                    @Override
////                                    public void run() {
////                                        if(tableView.getItems().size()>0 && PaneAndHBoxFrameAndProgressBar.progressBar.getProgress()==1 && index!=-1){
////                                            int one = index-250<0?0:index-250;
////                                            int tow = index+250>tableView.getItems().size()?tableView.getItems().size():index+250;
////                                            for(int i = one;i<tow;i++){
////                                                TagMemoryDataX86 temp = tableView.getItems().get(i);
////                                                String byteStr = Arrays.toString(MemoryOperationUtilsX86.readProcessMemoryByte(StageWindowsProcessAndListView.ProcessIDHandle,temp.tenAddress,20));
////                                                TagMemoryDataX86 tagMemoryDataX86 = new TagMemoryDataX86(temp.IsStatic,temp.tenAddress,temp.HexAddress,temp.MemoryProtect,temp.MemoryType,byteStr);
////                                                tableView.getItems().set(i,tagMemoryDataX86);
//////                                               tableView.setItems(data);
////                                            }
//////                                               flag=false;
////                                        }
////                                    }
////                                });
////                            }catch (Exception e){e.printStackTrace();}
////                        }
////                    }
////                });
////                flag=true;
////                thread.start();
//            }
//        });
    }
}


